// PreferencesDialog
// $Id: PreferencesDialog.java,v 1.14 2003/06/03 23:44:30 axelwernicke Exp $
//
// Copyright (C) 2002-2003 Axel Wernicke <axel.wernicke@gmx.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

package de.axelwernicke.mypod.gui;

import java.awt.CardLayout;
import java.util.Arrays;
import java.util.Iterator;

import javax.swing.JFileChooser;
import javax.swing.JTree;
import javax.swing.tree.TreePath;

import de.axelwernicke.mypod.Preferences;


/**
 * Preferences Dialog
 * @author axel wernicke
 */
public class PreferencesDialog extends javax.swing.JDialog {
    /** jdk1.4 logger */

    //private static Logger logger = Logger.getLogger("de.axelwernicke.mypod.gui.PreferencesDialog" );
    private java.awt.Frame parent;
    private boolean confirmed;
    private java.util.Map<String, String> lookAndFeelInfo;

    /** Creates new form PreferencesDialog.
     *
     * @param _parent frame the dialog window is attached to
     * @param modal if true, the dialog is modal
     */
    public PreferencesDialog(java.awt.Frame _parent, boolean modal) {
        // init
        super(_parent, modal);

        parent = _parent;

        lookAndFeelInfo = GuiUtils.getLookAndFeelInfo();

        initComponents();

        getRootPane().setDefaultButton(OkButton);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() //GEN-BEGIN:initComponents
     {
        java.awt.GridBagConstraints gridBagConstraints;

        splitPane = new javax.swing.JSplitPane();
        treeScrollPane = new javax.swing.JScrollPane();
        optionTree = new javax.swing.JTree();
        contentPanel = new javax.swing.JPanel();
        generalScrollPane = new javax.swing.JScrollPane();
        generalPanel = new javax.swing.JPanel();
        lookAndFeelLabel = new javax.swing.JLabel();
        lfComboBox = new javax.swing.JComboBox();
        clipsTableLabel = new javax.swing.JLabel();
        optimizeWidthCheckBox = new javax.swing.JCheckBox();
        hideEmptyColumnsCheckBox = new javax.swing.JCheckBox();
        dummyPanel = new javax.swing.JPanel();
        ipodScrollPane = new javax.swing.JScrollPane();
        ipodPanel = new javax.swing.JPanel();
        syncIpodLabel = new javax.swing.JLabel();
        ipodPathTextField = new javax.swing.JTextField();
        ipodPathButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        externalPlayerScrollPane = new javax.swing.JScrollPane();
        externalPlayerPanel = new javax.swing.JPanel();
        externalPlayerPathLabel = new javax.swing.JLabel();
        externalPlayerPathTextField = new javax.swing.JTextField();
        externalPlayerPathButton = new javax.swing.JButton();
        parameterLabel = new javax.swing.JLabel();
        addEnabledCheckBox = new javax.swing.JCheckBox();
        addParameterTextField = new javax.swing.JTextField();
        appendEnabledCheckBox = new javax.swing.JCheckBox();
        appendParameterTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        buttonPanel = new javax.swing.JPanel();
        OkButton = new javax.swing.JButton();
        CancelButton = new javax.swing.JButton();

        setTitle(GuiUtils.getStringLocalized("resource/language", "myPodPreferences"));
        setName("PreferencesDialog");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    closeDialog(evt);
                }
            });

        splitPane.setDividerLocation(150);
        splitPane.setMinimumSize(new java.awt.Dimension(200, 50));
        splitPane.setPreferredSize(new java.awt.Dimension(500, 300));
        treeScrollPane.setMinimumSize(new java.awt.Dimension(150, 22));
        treeScrollPane.setPreferredSize(new java.awt.Dimension(150, 22));
        optionTree.setMinimumSize(new java.awt.Dimension(145, 72));
        optionTree.setPreferredSize(new java.awt.Dimension(145, 72));
        optionTree.setRootVisible(false);
        optionTree.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    optionTreeMouseClicked(evt);
                }
            });
        optionTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
                public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                    optionTreeValueChanged(evt);
                }
            });

        treeScrollPane.setViewportView(optionTree);

        splitPane.setLeftComponent(treeScrollPane);

        contentPanel.setLayout(new java.awt.CardLayout());

        contentPanel.setMinimumSize(new java.awt.Dimension(85, 47));
        contentPanel.setPreferredSize(new java.awt.Dimension(475, 220));
        generalScrollPane.setBorder(null);
        generalPanel.setLayout(new java.awt.GridBagLayout());

        lookAndFeelLabel.setForeground(new java.awt.Color(102, 102, 153));
        lookAndFeelLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lookAndFeelLabel.setText(GuiUtils.getStringLocalized("resource/language", "lookAndFeel:"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
        generalPanel.add(lookAndFeelLabel, gridBagConstraints);

        lfComboBox.setMinimumSize(new java.awt.Dimension(100, 25));
        lfComboBox.setPreferredSize(new java.awt.Dimension(250, 25));
        initLookAndFeelComboBox();
        lfComboBox.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
                public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                }

                public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                    lfComboBoxPopupMenuWillBecomeInvisible(evt);
                }

                public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
                }
            });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 23, 0, 0);
        generalPanel.add(lfComboBox, gridBagConstraints);

        clipsTableLabel.setForeground(new java.awt.Color(102, 102, 153));
        clipsTableLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        clipsTableLabel.setText(GuiUtils.getStringLocalized("resource/language", "listView:"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 12, 0, 0);
        generalPanel.add(clipsTableLabel, gridBagConstraints);

        optimizeWidthCheckBox.setText(GuiUtils.getStringLocalized("resource/language", "optimizeColumnWidth"));
        optimizeWidthCheckBox.addChangeListener(new javax.swing.event.ChangeListener() {
                public void stateChanged(javax.swing.event.ChangeEvent evt) {
                    optimizeWidthCheckBoxStateChanged(evt);
                }
            });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 23, 0, 12);
        generalPanel.add(optimizeWidthCheckBox, gridBagConstraints);

        hideEmptyColumnsCheckBox.setText(GuiUtils.getStringLocalized("resource/language", "hideEmptyColumns"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 23, 0, 12);
        generalPanel.add(hideEmptyColumnsCheckBox, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        generalPanel.add(dummyPanel, gridBagConstraints);

        generalScrollPane.setViewportView(generalPanel);

        contentPanel.add(generalScrollPane, "generalCard");

        ipodScrollPane.setBorder(null);
        ipodPanel.setLayout(new java.awt.GridBagLayout());

        syncIpodLabel.setForeground(new java.awt.Color(102, 102, 153));
        syncIpodLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        syncIpodLabel.setText(GuiUtils.getStringLocalized("resource/language", "pathToIpod:"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
        ipodPanel.add(syncIpodLabel, gridBagConstraints);

        ipodPathTextField.setEditable(false);
        ipodPathTextField.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        ipodPathTextField.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 2.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 23, 0, 0);
        ipodPanel.add(ipodPathTextField, gridBagConstraints);

        ipodPathButton.setText("...");
        ipodPathButton.setMinimumSize(new java.awt.Dimension(81, 20));
        ipodPathButton.setPreferredSize(new java.awt.Dimension(30, 20));
        ipodPathButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ipodPathButtonActionPerformed(evt);
                }
            });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 2, 0, 12);
        ipodPanel.add(ipodPathButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.weighty = 1.0;
        ipodPanel.add(jPanel1, gridBagConstraints);

        ipodScrollPane.setViewportView(ipodPanel);

        contentPanel.add(ipodScrollPane, "ipodCard");

        externalPlayerScrollPane.setBorder(null);
        externalPlayerPanel.setLayout(new java.awt.GridBagLayout());

        externalPlayerPathLabel.setForeground(new java.awt.Color(102, 102, 153));
        externalPlayerPathLabel.setText(GuiUtils.getStringLocalized("resource/language", "externalPlayerPath:"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
        externalPlayerPanel.add(externalPlayerPathLabel, gridBagConstraints);

        externalPlayerPathTextField.setEditable(false);
        externalPlayerPathTextField.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(5, 23, 0, 0);
        externalPlayerPanel.add(externalPlayerPathTextField, gridBagConstraints);

        externalPlayerPathButton.setText("...");
        externalPlayerPathButton.setMinimumSize(new java.awt.Dimension(81, 20));
        externalPlayerPathButton.setPreferredSize(new java.awt.Dimension(30, 20));
        externalPlayerPathButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    externalPlayerPathButtonActionPerformed(evt);
                }
            });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 2, 0, 12);
        externalPlayerPanel.add(externalPlayerPathButton, gridBagConstraints);

        parameterLabel.setForeground(new java.awt.Color(102, 102, 153));
        parameterLabel.setText(GuiUtils.getStringLocalized("resource/language", "parameter:"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 12, 0, 0);
        externalPlayerPanel.add(parameterLabel, gridBagConstraints);

        addEnabledCheckBox.setText(GuiUtils.getStringLocalized("resource/language", "AddToPlayer"));
        addEnabledCheckBox.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        addEnabledCheckBox.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    addEnabledCheckBoxActionPerformed(evt);
                }
            });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 23, 0, 0);
        externalPlayerPanel.add(addEnabledCheckBox, gridBagConstraints);

        addParameterTextField.addFocusListener(new java.awt.event.FocusAdapter() {
                public void focusLost(java.awt.event.FocusEvent evt) {
                    addParameterTextFieldFocusLost(evt);
                }
            });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 11, 0, 0);
        externalPlayerPanel.add(addParameterTextField, gridBagConstraints);

        appendEnabledCheckBox.setText(GuiUtils.getStringLocalized("resource/language", "appendToPlayer"));
        appendEnabledCheckBox.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        appendEnabledCheckBox.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    appendEnabledCheckBoxActionPerformed(evt);
                }
            });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 23, 0, 0);
        externalPlayerPanel.add(appendEnabledCheckBox, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 11, 0, 0);
        externalPlayerPanel.add(appendParameterTextField, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 5;
        gridBagConstraints.weighty = 0.1;
        externalPlayerPanel.add(jLabel1, gridBagConstraints);

        externalPlayerScrollPane.setViewportView(externalPlayerPanel);

        contentPanel.add(externalPlayerScrollPane, "externalPlayerCard");

        splitPane.setRightComponent(contentPanel);

        getContentPane().add(splitPane, java.awt.BorderLayout.CENTER);

        OkButton.setText(GuiUtils.getStringLocalized("resource/language", "ok"));
        OkButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    OkButtonActionPerformed(evt);
                }
            });

        buttonPanel.add(OkButton);

        CancelButton.setText(GuiUtils.getStringLocalized("resource/language", "cancel"));
        CancelButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    CancelButtonActionPerformed(evt);
                }
            });

        buttonPanel.add(CancelButton);

        getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);

        pack();
    } //GEN-END:initComponents

    private void optionTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) //GEN-FIRST:event_optionTreeValueChanged
     { //GEN-HEADEREND:event_optionTreeValueChanged
        try {
            TreePath tpath = evt.getNewLeadSelectionPath();
            String leaf = tpath.getLastPathComponent().toString();

            // show card selected
            showCard(leaf);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } //GEN-LAST:event_optionTreeValueChanged

    /** enable or disable item, depending on the optimize width checkbox selection
     * @param evt
     */
    private void optimizeWidthCheckBoxStateChanged(javax.swing.event.ChangeEvent evt) //GEN-FIRST:event_optimizeWidthCheckBoxStateChanged
     { //GEN-HEADEREND:event_optimizeWidthCheckBoxStateChanged
        this.hideEmptyColumnsCheckBox.setEnabled(this.optimizeWidthCheckBox.isSelected());
    } //GEN-LAST:event_optimizeWidthCheckBoxStateChanged

    /** Change look and fell as soon as user selected one in the combobox
     * @param evt
     */
    private void lfComboBoxPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) //GEN-FIRST:event_lfComboBoxPopupMenuWillBecomeInvisible
     { //GEN-HEADEREND:event_lfComboBoxPopupMenuWillBecomeInvisible
        GuiUtils.setLookAndFeel(this.lookAndFeelInfo.get(this.lfComboBox.getSelectedItem()), parent);
    } //GEN-LAST:event_lfComboBoxPopupMenuWillBecomeInvisible

    /** Initialize the items for the look and feel selection
     */
    private void initLookAndFeelComboBox() {
        // sort all available look and feels ...
        Object[] keys = this.lookAndFeelInfo.keySet().toArray();
        Arrays.sort(keys);

        // ... and add them to the combo box
        for (int i = 0; i < keys.length; i++) {
            this.lfComboBox.addItem(keys[i]);
        }
    }

    /** Get iPod path from file chooser...
     * @param evt
     */
    private void ipodPathButtonActionPerformed(java.awt.event.ActionEvent evt) //GEN-FIRST:event_ipodPathButtonActionPerformed
     { //GEN-HEADEREND:event_ipodPathButtonActionPerformed
        // get a file selection dialog
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle(GuiUtils.getStringLocalized("resource/language", "selectPathToIPod"));
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setMultiSelectionEnabled(false);
        int result = fc.showDialog(this, "Select");

        // set selection (if any) to text field
        if (result == JFileChooser.APPROVE_OPTION) {
            this.ipodPathTextField.setText(fc.getSelectedFile().getPath());
        }
    } //GEN-LAST:event_ipodPathButtonActionPerformed

    /** Get external player path from file chooser
     * @param evt
     */
    private void externalPlayerPathButtonActionPerformed(java.awt.event.ActionEvent evt) //GEN-FIRST:event_externalPlayerPathButtonActionPerformed
     { //GEN-HEADEREND:event_externalPlayerPathButtonActionPerformed
        // get a file selection dialog
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle(GuiUtils.getStringLocalized("resource/language", "selectExternalPlayer"));
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.setMultiSelectionEnabled(true);
        int result = fc.showOpenDialog(this);

        // set selection (if any) to text field
        if (result == JFileChooser.APPROVE_OPTION) {
            this.externalPlayerPathTextField.setText(fc.getSelectedFile().getPath());
        }
    } //GEN-LAST:event_externalPlayerPathButtonActionPerformed

    /**
     * @param evt
     */
    private void addParameterTextFieldFocusLost(java.awt.event.FocusEvent evt) //GEN-FIRST:event_addParameterTextFieldFocusLost
     { //GEN-HEADEREND:event_addParameterTextFieldFocusLost
    } //GEN-LAST:event_addParameterTextFieldFocusLost

    /** enable append parameter text box when checkbox is selected
     * @param evt
     */
    private void appendEnabledCheckBoxActionPerformed(java.awt.event.ActionEvent evt) //GEN-FIRST:event_appendEnabledCheckBoxActionPerformed
     { //GEN-HEADEREND:event_appendEnabledCheckBoxActionPerformed
        appendParameterTextField.setEnabled(appendEnabledCheckBox.getModel().isSelected());
    } //GEN-LAST:event_appendEnabledCheckBoxActionPerformed

    /** enable add parameter text box when checkbox is selected
     * @param evt
     */
    private void addEnabledCheckBoxActionPerformed(java.awt.event.ActionEvent evt) //GEN-FIRST:event_addEnabledCheckBoxActionPerformed
     { //GEN-HEADEREND:event_addEnabledCheckBoxActionPerformed
        addParameterTextField.setEnabled(addEnabledCheckBox.getModel().isSelected());
    } //GEN-LAST:event_addEnabledCheckBoxActionPerformed

    /** Show option card selected in the option tree
     * @param evt
     */
    private void optionTreeMouseClicked(java.awt.event.MouseEvent evt) //GEN-FIRST:event_optionTreeMouseClicked
     { //GEN-HEADEREND:event_optionTreeMouseClicked
        try {
            // determine which object was clicked
            JTree jtree = (JTree) evt.getSource();
            String leaf = jtree.getSelectionPath().getLastPathComponent().toString();

            // show card
            showCard(leaf);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } //GEN-LAST:event_optionTreeMouseClicked

    /**
     * @param evt
     */
    private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) //GEN-FIRST:event_CancelButtonActionPerformed
     { //GEN-HEADEREND:event_CancelButtonActionPerformed
        confirmed = false;
        setVisible(false);
    } //GEN-LAST:event_CancelButtonActionPerformed

    /** Handle OK button clicks
     * @param evt
     */
    private void OkButtonActionPerformed(java.awt.event.ActionEvent evt) //GEN-FIRST:event_OkButtonActionPerformed
     { //GEN-HEADEREND:event_OkButtonActionPerformed
        confirmed = true;
        setVisible(false);
    } //GEN-LAST:event_OkButtonActionPerformed

    /** Closes the dialog
     * @param evt
     */
    private void closeDialog(java.awt.event.WindowEvent evt) { //GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    } //GEN-LAST:event_closeDialog

    /** check if the dialog was confirmed by the user
     * @return true, if user closed dialog via ok button
     */
    boolean isConfirmed() {
        return confirmed;
    }

    /** Set values in the dialog from preferences object
     *
     * @param prefs preferences to set
     */
    void setPreferences(Preferences prefs) {
        // init general values
        this.optimizeWidthCheckBox.setSelected(prefs.isOptimizeColumnWidth());
        this.hideEmptyColumnsCheckBox.setSelected(prefs.isHideEmptyColumns());
        this.hideEmptyColumnsCheckBox.setEnabled(prefs.isOptimizeColumnWidth());

        // init iPod values
        this.ipodPathTextField.setText(prefs.getIPodPath());

        // init external player values
        this.externalPlayerPathTextField.setText(prefs.getPlayerPath());
        this.addEnabledCheckBox.getModel().setSelected(prefs.isAddEnabled());
        this.addParameterTextField.setText(prefs.getAddParameter());
        this.appendEnabledCheckBox.getModel().setSelected(prefs.isAppendEnabled());
        this.appendParameterTextField.setText(prefs.getAppendParameter());
        this.addParameterTextField.setEnabled(prefs.isAddEnabled());
        this.appendParameterTextField.setEnabled(prefs.isAppendEnabled());

        // search the lf name for the class in the preferences
        String name = null;
        String key = null;
        Iterator<String> iter = this.lookAndFeelInfo.keySet().iterator();
        while ((name == null) && iter.hasNext()) {
            key = iter.next();
            if (this.lookAndFeelInfo.get(key).equals(prefs.getLookAndFeelName())) {
                name = key;
            }
        }
        this.lfComboBox.setSelectedItem(name);
    }

    /** Gets preferences object from values in the dialog.
     *
     * @return preferences from dialog
     */
    Preferences getPrefs() {
        Preferences prefs = new Preferences();

        // get values
        prefs.setAddEnabled(addEnabledCheckBox.getModel().isSelected());
        prefs.setAddParameter(addParameterTextField.getText());
        prefs.setAppendEnabled(appendEnabledCheckBox.getModel().isSelected());
        prefs.setAppendParameter(appendParameterTextField.getText());
        prefs.setPlayerPath(externalPlayerPathTextField.getText());
        prefs.setIPodPath(ipodPathTextField.getText());
        prefs.setLookAndFeelName(this.lookAndFeelInfo.get(this.lfComboBox.getSelectedItem()));
        prefs.setOptimizeColumnWidth(this.optimizeWidthCheckBox.isSelected());
        prefs.setHideEmptyColumns(this.hideEmptyColumnsCheckBox.isSelected());

        return prefs;
    }

    /** Show card by its name
     */
    private void showCard(String cardName) {
        // set property card
        CardLayout cardLayout = (CardLayout) contentPanel.getLayout();

        if (cardName.equals(GuiUtils.getStringLocalized("resource/language", "general"))) {
            contentPanel.repaint();
            cardLayout.show(this.contentPanel, "generalCard");
        } else if (cardName.equals(GuiUtils.getStringLocalized("resource/language", "ipod"))) {
            contentPanel.repaint();
            cardLayout.show(this.contentPanel, "ipodCard");
        } else if (cardName.equals(GuiUtils.getStringLocalized("resource/language", "externalPlayer"))) {
            contentPanel.repaint();
            cardLayout.show(this.contentPanel, "externalPlayerCard");
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CancelButton;
    private javax.swing.JButton OkButton;
    private javax.swing.JCheckBox addEnabledCheckBox;
    private javax.swing.JTextField addParameterTextField;
    private javax.swing.JCheckBox appendEnabledCheckBox;
    private javax.swing.JTextField appendParameterTextField;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JLabel clipsTableLabel;
    private javax.swing.JPanel contentPanel;
    private javax.swing.JPanel dummyPanel;
    private javax.swing.JPanel externalPlayerPanel;
    private javax.swing.JButton externalPlayerPathButton;
    private javax.swing.JLabel externalPlayerPathLabel;
    private javax.swing.JTextField externalPlayerPathTextField;
    private javax.swing.JScrollPane externalPlayerScrollPane;
    private javax.swing.JPanel generalPanel;
    private javax.swing.JScrollPane generalScrollPane;
    private javax.swing.JCheckBox hideEmptyColumnsCheckBox;
    private javax.swing.JPanel ipodPanel;
    private javax.swing.JButton ipodPathButton;
    private javax.swing.JTextField ipodPathTextField;
    private javax.swing.JScrollPane ipodScrollPane;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox lfComboBox;
    private javax.swing.JLabel lookAndFeelLabel;
    private javax.swing.JCheckBox optimizeWidthCheckBox;
    public javax.swing.JTree optionTree;
    private javax.swing.JLabel parameterLabel;
    private javax.swing.JSplitPane splitPane;
    private javax.swing.JLabel syncIpodLabel;
    private javax.swing.JScrollPane treeScrollPane;

    // End of variables declaration//GEN-END:variables
}
